<h5 translate>whoCanAccess</h5>

<!--Message alert-->
<div ng-if="alertMsg" class="alert alert-warning"
     role="alert"
     translate>privilegesBatchAlert
</div>

<!--Search inpup-->
<div class="col-md-4 input-group input-group-sm gn-searchgroup-input">
  <span class="input-group-addon" translate>filter</span>
  <input type="text" class="form-control input-sm" ng-model="pFilter"
         ng-model-options="{debounce: 300}" placeholder="{{'filterGroup' | translate}}">
</div>


<!-- TODO: simplify layout if only one group -->
<div class="gn-share-grid">
  <i class="fa fa-spinner fa-spin" data-ng-hide="privileges.length > 0"></i>

  <form name="opsForm" id="opsForm"
        data-ng-class="{'gn-sharing-batch': batch}">
              <input type="hidden" name="_csrf" value="{{csrf}}"/>
    <table class="table table-striped" data-ng-show="privileges.length > 0">
      <thead>
      <tr>
        <th>
          <a href="" ng-click="setSorter('g')">
            <span translate>groupOwners</span>&nbsp;
            <i data-ng-if="sorter.predicate == 'g'" class="fa"
             ng-class="sorter.reverse ? 'fa-long-arrow-up' : 'fa-long-arrow-down'"></i>
          </a>
        </th>
        <th data-ng-repeat="key in operations">
          <a href="" ng-click="setSorter(key)">
            <i class="fa {{icons[key] || fa-fw}}"/>
            <span class="hidden-xs">&nbsp;{{('op-' + key) | translate}}&nbsp;</span>
            <i data-ng-if="sorter.predicate == key" class="fa"
               data-ng-class="sorter.reverse ? 'fa-long-arrow-down' : 'fa-long-arrow-up'"></i>
          </a>
        </th>
        <th data-ng-if="!disableAllCol">
          <span class="visible-xs">
            <i class="fa fa-fw fa-lock"></i>
          </span>
          <span class="hidden-xs" translate>setall</span>
        </th>
        <th data-ng-if="displayProfile"><a href="" ng-click="setSorter('p')">
          <span translate>profile</span>&nbsp;
          <i data-ng-if="sorter.predicate == 'p'" class="fa"
             ng-class="sorter.reverse ? 'fa-long-arrow-up' : 'fa-long-arrow-down'"></i>
        </a>
        </th>
      </tr>
      </thead>
      <tbody>
      <tr class="info"
          data-ng-repeat="g in privileges | filter:{reserved: true} | orderBy:'id':true">
        <td><strong>{{('group-' + g.group) | translate}}</strong></td>
        <td data-ng-repeat="key in operations" class="text-center">
          <input type="checkbox"
                 name="{{g.group + '-' + key}}"
                 data-ng-disabled="!isAdminOrReviewer"
                 data-ng-class="internalGroups.indexOf(g.group) != -1 &&
                                internalOperations.indexOf(key) != -1 ? 'hidden' : ''"
                 data-ng-model="g.operations[key]"/>
        </td>
        <td data-ng-if="!disableAllCol">
          <input type="checkbox"
                 data-ng-disabled="!isAdminOrReviewer"
                 data-ng-click="checkAll(g)"
                 data-ng-model="g.isCheckedAll"/>
        </td>
        <td class="text-center" data-ng-if="displayProfile">

        </td>
      </tr>
      <tr
        data-ng-repeat="g in privileges | filter:{reserved: false} | filter:pFilterFn | orderBy:sortGroups:sorter.reverse"
        data-ng-show="(onlyUserGroup == true && g.userGroup == true) ||
                       onlyUserGroup == false">
        <td><strong>{{('group-' + g.group) | translate}}</strong></td>
        <td data-ng-repeat="key in operations" class="text-center">
          <input type="checkbox"
                 name="{{g.group + '-' + key}}"
                 data-ng-disabled="g.privileges[key].disabled"
                 data-ng-model="g.operations[key]"/>
        </td>
        <td data-ng-if="!disableAllCol">
          <input type="checkbox"
                 data-ng-click="checkAll(g)"
                 data-ng-model="g.isCheckedAll"/>
        </td>
        <td class="text-center" data-ng-if="displayProfile">
          <span data-ng-repeat="p in g.userProfiles">
            {{user.isAdministrator() ? ('Administrator' | translate) : (p | translate)}}&nbsp;
          </span>
        </td>

      </tr>
      </tbody>
    </table>
  </form>
</div>

<div class="btn-toolbar pull-right">
  <div data-gn-need-help="user-guide/publishing/index.html"
       data-icon-only="true"></div> 
  <button type="button" class="btn btn-primary"
          id="gn-share-btn-replace"
          data-gn-click-and-spin="save(true)">
    <i class="fa fa-eraser"></i>&nbsp;
    <span data-translate="">replaceByThoseOperations</span>
  </button>
  <button type="button" class="btn btn-primary"
          id="gn-share-btn-add"
          data-gn-click-and-spin="save(false)"
          data-ng-show="batch">
    <i class="fa fa-plus"></i>&nbsp;
    <span data-translate="">addThoseOperations</span>
  </button>
  <button type="button" class="btn btn-default"
          id="gn-share-btn-reset"
          data-ng-click="reset()"
          data-ng-show="batch"
          title="{{'resetOps' | translate}}">
    <i class="fa fa-undo"></i>&nbsp;
  </button>
</div>
